package com.usian.order.listener;



import com.rabbitmq.client.Channel;
import com.usian.jyzx.model.entity.pay.PaymentInfo;
import com.usian.order.mapper.OrderInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 07 19 15 03
 **/
@Component
@Slf4j
public class PayLister {

    @Autowired
    OrderInfoMapper orderInfoMapper;

    @RabbitListener(queuesToDeclare = @Queue("pay-queue"))
    @RabbitHandler
    public String testConsumer(PaymentInfo paymentInfo, Channel channel, Message message) throws Exception {
        log.info("PayLister消费消息:{}", paymentInfo.toString());


        String orderNo = paymentInfo.getOrderNo();
        orderInfoMapper.updateOrderStatus(orderNo,1);

        /**
         * ACK，用的最多的一种
         * deliveryTag:该消息的index
         * false:表示不是批量
         */
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

        return "消费-result";
    }
}
